<template>
	<view class="college">
		<view class="headtop">
			<view class="headtitile">
				<image src="../../../static/images/left.png" @click="fanhui"></image>
				<text @click="fanhui">AI学院</text>
			</view>
		</view>
		<view class="nav clearfix">
			<view :class="[activeIndex == 1?'active':'']" @click="qiehuan(1)">
				<view class="name">新手教程</view>
				<view class="hengxian"></view>
			</view>
			<view :class="[activeIndex == 2?'active':'']" @click="qiehuan(2)">
				<view class="name">团购知识</view>
				<view class="hengxian"></view>
			</view>
			<view :class="[activeIndex == 3?'active':'']" @click="qiehuan(3)">
				<view class="name">官方公告</view>
				<view class="hengxian"></view>
			</view>
		</view>
		<view class="container" v-if="list.length">
			<view class="list clearfix" v-for="(item,index) in list" :key="index" @click="detail(index)">
				<view class="left fl">
					<image :src="'https://groupbuy.huishuokj.com/upload/' + item.thumbnail" class="image"></image>
					<image src="../../../static/images/mengban.png" class="mengban" v-if="item.attr == 1"></image>
				</view>
				<view class="right fl">
					<view class="title">{{item.title}}</view>
					<view class="time">{{item.create_time}}</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image src="../../../static/images/empty.png" mode="widthFix"></image>
		</view>

		<view class="beijing" v-if="hidden"></view>
		<view class="tankuang" v-if="hidden">
			<image src="../../../static/images/guanbi.png" class="close" @click="guanbi"></image>
			<video :src="video_url" controls="true" autoplay="false"></video>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/api/request';

	export default {
		data() {
			return {
				activeIndex: 1,
				page: 1,
				list: [],
				hidden: false,
				video_url: '',
			}
		},
		onLoad() {
			this.getList(1, this.activeIndex)
		},
		onReachBottom() {
			this.page++;
			this.getList(this.page, this.activeIndex)
		},
		methods: {
			getList(page, type) {
				let that = this;

				request({
					url: '/api/article/top',
					method: 'POST',
					data: {
						page: page,
						type: type,
					},
				}).then((response) => {
					if (response.data.list) {
						let list = response.data.list;

						that.list.push(...list)
					}
				}).catch((error) => {});
			},
			qiehuan(index) {
				this.activeIndex = index;

				this.list = [];
				this.page = 1;

				this.getList(1, this.activeIndex);
			},
			detail(index) {
				let attr = this.list[index].attr;
				let id = this.list[index].id;

				if (attr == 1) {
					// 视频
					this.video_url = this.list[index].url;

					this.hidden = !this.hidden;
				} else {
					uni.navigateTo({
						url: '/pages/user/second/college_detail?id=' + id
					})
				}
			},
			guanbi() {
				this.video_url = '';
				this.hidden = !this.hidden;
			},
			fanhui() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.college {
		width: 100%;
		margin: 0 auto;

		.headtop {
			width: 100%;
			margin: 0 auto;
			position: relative;
			height: 166rpx;
			z-index: 200;

			.headtitile {
				width: 94%;
				margin: 0 auto;
				position: absolute;
				top: 60rpx;
				left: 3%;
				height: 96rpx;
				line-height: 96rpx;

				image {
					width: 20rpx;
					height: 36rpx;
					float: left;
					margin-right: 18rpx;
					margin-top: 28rpx;
				}

				text {
					font-size: 32rpx;
					color: #FFFFFF;
					float: left;
					height: 96rpx;
					line-height: 96rpx;
				}

				view {
					font-size: 30rpx;
					color: #ECDEA4;
					float: right;
					height: 96rpx;
					line-height: 96rpx;
				}
			}
		}

		.nav {
			width: 94%;
			margin: 0 auto;

			>view {
				float: left;
				width: 33.3%;

				.name {
					font-size: 28rpx;
					height: 70rpx;
					line-height: 70rpx;
					color: #787B8F;
				}

				.hengxian {
					width: 110rpx;
					margin: 0 auto;
					height: 2rpx;
					background: #191D26;
				}
			}

			.active {

				.name {
					color: #FFFFFF;
				}

				.hengxian {
					background: #FFFFFF;
				}
			}

			>view:nth-of-type(1) {
				padding-left: 20rpx;
				box-sizing: border-box;
				text-align: left;

				.hengxian {
					margin-left: 0;
				}
			}

			>view:nth-of-type(2) {
				text-align: center;
			}

			>view:nth-of-type(3) {
				padding-right: 20rpx;
				box-sizing: border-box;
				text-align: right;

				.hengxian {
					margin-right: 0;
				}
			}
		}

		.container {
			width: 94%;
			margin: 0 auto;
			margin-top: 30rpx;

			.list {
				width: 100%;
				margin-bottom: 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				background: #242831;
				border-radius: 10rpx;

				.left {
					width: 250rpx;
					height: 140rpx;
					position: relative;
					border-radius: 10rpx;
					margin-right: 20rpx;

					.image {
						width: 100%;
						height: 140rpx;
						border-radius: 10rpx;
					}

					.mengban {
						width: 100%;
						height: 140rpx;
						border-radius: 10rpx;
						position: absolute;
						top: 0;
						left: 0;
					}
				}

				.right {
					width: 56%;

					.title {
						font-size: 30rpx;
						color: #FFFFFF;
						margin-top: 10rpx;
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.time {
						font-size: 24rpx;
						color: #787B8F;
						margin-top: 50rpx;
					}
				}
			}
		}

		.beijing {
			position: fixed;
			top: 0;
			left: 0;
			background: #000;
			opacity: 0.5;
			z-index: 210;
			width: 100%;
			height: 100vh;
		}

		.tankuang {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 220;
			width: 100%;
			height: 100vh;

			.close {
				width: 30rpx;
				height: 30rpx;
				margin-top: 20rpx;
				margin-bottom: 10rpx;
				float: right;
				margin-right: 20rpx;
			}

			video {
				width: 100%;
				height: 94vh;
			}
		}

		.empty {
			width: 94%;
			margin: 300rpx auto;
			text-align: center;

			image {
				width: 300rpx;
			}
		}
	}
</style>